//
//  GalleryViewController.m
//  somenew
//
//  Created by Koby5 on 12/19/12.
//  Copyright (c) 2012 Koby5. All rights reserved.
//

#import "GalleryViewController.h"

#define SCROLL_SPEED 1 //items per second

@implementation GalleryViewController

@synthesize carousel;
@synthesize iCarousel;
@synthesize animals;
@synthesize wrap;
@synthesize carouselView;
@synthesize PrevImageBtn, NextImageBtn;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [ super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if(self)
    {
        self.title = NSLocalizedString(@"Gallery", @"");
        self.tabBarItem.image = [UIImage imageNamed:@"img2"];
        
        wrap = true;
        self.animals = [NSMutableArray arrayWithObjects:@"Bear.png",
                        @"Zebra.png",
                        @"Tiger.png",
                        @"Goat.png",
                        @"Birds.png",
                        @"Giraffe.png",
                        @"Chimp.png",
                        nil];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self initGallery];
}

-(void)initGallery
{
    carousel.type = iCarouselTypeCoverFlow;/*You can change this*/
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)dealloc
{
    [PrevImageBtn release];
    [NextImageBtn release];
    [iCarousel release];
    [carouselView release];
    [super dealloc];
}
- (void)viewDidUnload
{
    [self setPrevImageBtn:nil];
    [self setNextImageBtn:nil];
    [self setICarousel:nil];
    [self setCarouselView:nil];
    [super viewDidUnload];
}

- (IBAction)PrevImageBtnClicked:(id)sender
{
    [carousel scrollToItemAtIndex:carousel.currentItemIndex-1 animated:YES];
}

- (IBAction)NextImageBtnClicked:(id)sender
{   
    [carousel scrollToItemAtIndex:carousel.currentItemIndex+1 animated:YES];
}

#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [animals count];
}

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    //limit the number of items views loaded concurrently (for performance reasons)
    return 7;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    //create a numbered view
	UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[animals objectAtIndex:index]]];
    [view setFrame:CGRectMake(0, 0, 320, 420)];/*x, x, width, height*/

	return view;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{    
    view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[animals objectAtIndex:index]]];
    [view setFrame:CGRectMake(0, 0, 320, 420)];/*x, x, width, height*/
    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
	//note: placeholder views are only displayed on some carousels if wrapping is disabled
	return 0;
}


- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    //usually this should be slightly wider than the item views
    return 320;
}


- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return wrap;
}

- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    switch (option)
    {
        case iCarouselOptionVisibleItems:
            return 3;
        case iCarouselOptionWrap:
            return 1.0f;
        default:
            return value;
    }
}

- (void)carouselDidEndScrollingAnimation:(iCarousel *)aCarousel
{
    //[label setText:[NSString stringWithFormat:@"%@", [descriptions objectAtIndex:aCarousel.currentItemIndex]]];/*Can use*/
}

@end
